package java_thinking.unit_12;

/**
 * @Description : 证明:派生类构造器不能捕获它的基类构造器所抛出的异常
 * @author: cww
 * @DateTime: 2019-03-24 16:05
 */
class Except1 extends Exception {
    public Except1(String s) {
        super(s);
    }
}

class BaseWithException {
    public BaseWithException() throws Except1 {
        throw new Except1("thrown by BaseWithException");
    }
}

/**
 * 派生构造器不能捕获基类构造器的异常
 */
class DerivedWE extends BaseWithException {
    // Produces compile-time error:
    //    unreported exception Except1

//    public DerivedWE() {}
    // Gives compile error: call to super must be
    // first statement in constructor:
    //! public DerivedWE() {
    //!   try {
    //!     super();
    //!   } catch(Except1 ex1) {
    //!   }
    //! }

    public DerivedWE() throws Except1 {}
}

public class E21 {
    public static void main(String[] args) {
        try {
            new DerivedWE();
        } catch (Except1 except1) {
            System.out.println("Caught "+except1);
        }
    }
}
